@extends('admin.conn.main')

@section('css')
    <style>
        .demo-miaosha{
            width: 400px;
            height:430px;
            background: white;
            border-radius: 10px;
            margin: 20px 0 0 70px;
            float: left;
        }
        .demo-img{
            margin: 0 auto;
            width: 200px;
            height: 250px
        }
    </style>
@endsection
@section('content')
<main class="lyear-layout-content">
    <div class="container-fluid">
        @foreach($data as $v)
            <div class="demo-miaosha">
                <h4 style="text-align: center;padding-top: 10px;font-family:'华文中宋' "><span style="color: red">秒杀倒计时</span>
                    <span id="h{{$v->id}}"></span>时
                    <span id="m{{$v->id}}"></span>分
                    <span id="s{{$v->id}}"></span>秒
                </h4>
                <div class="demo-img"><img src="{{$v->lw_pic}}" alt="" width="200" height="250"></div>
                <p style="text-align: center;padding-top: 10px"><b>商品名称：</b>{{$v->lw_name}}</p>
                <p style="text-align: center"><b>商品价格：</b>{{$v->lw_price}}</p>
                <p style="text-align: center"><button class="btn btn-danger btn-w-xl btn-primary" type="button" id="{{$v->id}}">抢购</button></p>
            </div>
        @endforeach
    </div>
</main>
@endsection
<!--End 页面主要内容-->
@section('js')
    <script type="text/javascript">
        $(document).ready(function (){
            //计时器
            window.setInterval(function (){
                $.ajax({
                    url: 'http://www.lw.com/index.php/admin/countdown',
                    type:'get',
                    dataType:'json',
                    success:function (data){
                        for (var i=0;i<data.length;i++){
                            id=data[i]['id'];
                            $('#h'+id).text(data[i]['hour']);
                            $('#m'+id).text(data[i]['minute']);
                            $('#s'+id).text(data[i]['second']);
                        }
                    }
                })
            },1000)
        })
        $(".btn").click(function (){
            var id=$(this).attr('id');
            $.ajax({
                url: 'http://www.lw.com/index.php/admin/behind',
                type:'get',
                dataType:'json',
                data:{'id':id},
                success:function (data){
                    if (data['code'] == 1){
                        alert(data['msg']);
                    }else{
                        alert(data['msg']);
                    }
                }
            })
        })
    </script>
@endsection